<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/common/taglibs.jsp"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<title>Mini-Web 帐号管理</title>
		<%@ include file="/common/meta.jsp"%>
		<link href="${staticCtx}/style/yui.css" type="text/css" rel="stylesheet" />
		<link href="${staticCtx}/style/style.css" type="text/css" rel="stylesheet" />
		<link href="${staticCtx}/script/jquery/validate/jquery.validate.css" type="text/css" rel="stylesheet" />
		<script src="${staticCtx}/script/jquery/jquery.js" type="text/javascript"></script>
		<script src="${staticCtx}/script/jquery/validate/jquery.validate.js" type="text/javascript"></script>
		<script src="${staticCtx}/script/jquery/validate/messages_cn.js" type="text/javascript"></script>
		<script>
		$(document).ready(function() {
		
			//聚焦第一个输入框
			$("#username").focus();
			//为inputForm注册validate函数
			$("#inputForm").validate({
				rules: {
					username:"required",
					password: {
						required: true,
						minlength:3
					},
					passwordConfirm: {
						equalTo:"#password"
					},
					//role:"required"
				},
				messages: {
					passwordConfirm: {
						equalTo: "输入与上面相同的密码"
					}
				}
			});
		});
	</script>
	</head>

	<body>
		<div id="doc3">
			<%@ include file="/common/header.jsp"%>
			<div id="bd">
				<div id="yui-main">
					<div class="yui-b">
						<h2>
							<c:choose>
								<c:when test="${user.id != null}">
									修改
								</c:when>
								<c:otherwise>
									创建
								</c:otherwise>
							</c:choose>
							用户
						</h2>
						<form id="inputForm" action="${ctx}/account/users" method="post">
							<input type="hidden" name="id" value="${user.id }" />
							<table class="noborder">
								<tr>
									<td>
										用户名:
									</td>
									<td>
										<c:choose>
											<c:when test="${user.id != null}">
												<span>${user.username}</span>
												<input type="hidden" name="username" id="username" value="${user.username}" />
											</c:when>
											<c:otherwise>
												<input type="text" name="username" id="username" value="${user.username}" />
											</c:otherwise>
										</c:choose>
									</td>
								</tr>
								<tr>
									<td>
										密码:
									</td>
									<td>
										<input type="password" id="password" name="password" value="${user.password}" />
									</td>
								</tr>
								<tr>
									<td>
										确认密码:
									</td>
									<td>
										<input type="password" id="passwordConfirm" name="passwordConfirm" value="${user.password}" />
									</td>
								</tr>
								<tr>
									<td>
										邮箱:
									</td>
									<td>
										<input type="text" id="email" name="email" value="${user.email}" />
									</td>
								</tr>
								<tr>
									<td>
										角色:
									</td>
									<td>
										<c:forEach items="${grantedRoleList}" var="grantedRole">
											<input type="checkbox" checked="checked" name="role" value="${grantedRole.id}" /> ${grantedRole.name}
										</c:forEach>
										<c:forEach items="${availiableRoleList}" var="role">
											<input type="checkbox" name="role" value="${role.id}" /> ${role.name}
										</c:forEach>
									</td>
								</tr>
								<tr>
									<td colspan="2">
										<security:authorize ifAnyGranted="ROLE_修改用户">
											<input class="button" type="submit" value="提交" />&nbsp;
					</security:authorize>
										<input class="button" type="button" value="返回" onclick="history.back()" />
									</td>
								</tr>
							</table>
						</form>
					</div>
				</div>
			</div>
			<%@ include file="/common/footer.jsp"%>
		</div>
	</body>
</html>
